<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function getMoney(arr) {
        if (arr.length == 0) {
          return 0
        }
        if (arr.length == 1) {
          return arr[0]
        }
        let dp = [arr[0], Math.max(arr[0], arr[1])]
        for (let i = 2; i < arr.length; i++) {
          dp[i] = Math.max(arr[i] + dp[i - 2], dp[i - 1])
        }
        console.log(dp)
        console.log(dp[arr.length - 1])
      }
      getMoney([2, 5, 1, 7, 5, 3, 5, 2])
    </script>
  </body>
</html>
